import ScrollBarLayout from '@/components/ScrollBarLayout';
import moment from 'moment';
import Cls from 'classnames';
import { useContext, useEffect, useMemo, useState } from 'react';
import pageStyles from '@/common/pageLayout.less';
import { DescriptionsType } from '@/components/DescriptionsType';
import {
  changeNumMoneyToChinese,
  wordHandChildParam,
  wordToChildParams,
  getKeyRouter,
  getTenantID,
  getPosIDs,
  getUserID,
  getLoadMapList,
  getInvoiceCode,
  getUserDepID,
} from '@/utils';
import { getUpdateConfig } from '../mconfig/UpdateConfig';
import { connect, history } from 'umi';
import { Col, Form, Row, Spin, message, Tabs, Button, Space, Card, Modal } from 'antd';
import { CheckCircleOutlined, SaveOutlined, QuestionCircleOutlined } from '@ant-design/icons';
import { OpenMaterialModal } from '../mconfig/OpenMaterialModal';
import { ToAssetControllerContext } from '../mconfig';
import { useToAssetControllerReducer, IToAssetControllerActionEnum } from '../mconfig';
import { addStorageService, editStorageService, submitStorageService, getDetailService, approvedToAssetSerivice } from '../services';
import { ILoadMapTypeAll, formatDecimal } from '@/common';
import { WorkflowChedkRecord, WorkflowHndTaskBtn, WorkflowNoDefaultTable, WorkflowSwitchModal } from '@/components/WorkflowCommonCopy';
import '../common/style.less';
import { BGflowBusinessType, orderType, requestController } from '../common/Format';
import { ContractModal } from '../mconfig/ContractModal';
import { getFlowOrgTreeByOrgIDService, getUserDataList } from '@/services/BaseLayout';
import { DetailInfoViewBottomBtn } from '../mconfig/DetailInfoViewBottomBtn';
import { RevokeModal } from '../../Acomponents/RevokeModal';

const ToAssetControllerUpdateView: React.FC<any> = ({ curRes, locationProps }) => {
  /** 引入上下文 */
  const { materielList, contractList, addMatrielList, toAssetControllerDispatch } = useToAssetControllerReducer();
  /** 样式根目录 */
  const { prefixCls, styleFixCls } = useContext(ToAssetControllerContext);

  /**  获取数据字典 */
  const { loadMapInfo, mapLoading } = getLoadMapList([
    `${getTenantID()}${ILoadMapTypeAll.MATERIAL_TYPE}`, //资产类型
    `${getTenantID()}${ILoadMapTypeAll.AVERAGE_LIFE_METHOD}`, //折旧方式
    `${getTenantID()}${ILoadMapTypeAll.ASSET_SOURCE_TYPE}`, //资产来源
    `${getTenantID()}${ILoadMapTypeAll.MATERIAL_BRAND}`, //资产品牌
    `${getTenantID()}${ILoadMapTypeAll.ASSET_AREA}`, //资产存放区域
    `${getTenantID()}${ILoadMapTypeAll.MATERIAL_MIDI}`, //计量单位
    `${getTenantID()}${ILoadMapTypeAll.ASSET_USED}`, //资产用途
  ]);

  /** 表单 */
  const [contractForm] = Form.useForm();
  /** 打开选择材料列表 */
  const [openMaterialModal, setOpenMaterialModal] = useState<boolean>(false);
  /** 打开选择合同列表 */
  const [contractVisible, setContractVisible] = useState<boolean>(false);
  /** 选中的单位ID */
  const [selectUserInfo, setSelectUserInfo] = useState<Record<string, any>>({});
  /** 详情数据 */
  const [detailInfo, setDetailInfo] = useState<any>({});
  /** 是否提交状态 */
  const [submitState, setSubmitState] = useState<boolean>(false);
  /** 工作流 */
  const [isShowWorkRecord, setIsShowWorkRecord] = useState<boolean>(false);
  const [showSwitchFlow, setShowSwitchFlow] = useState<boolean>(false);
  const [workFlowInfoObj, setWorkFlowInfoObj] = useState<Record<string, any>>({
    selectFlowRows: {},
    showWorkFlowModal: false,
    saveNoDefaultFlowID: '',
  });

  /** 材料转资产审批同意判断是否可以调用同步接口 */
  const [auditSuccessState, setAuditSuccessState] = useState(false);

  /** 获取组织机构树接口 */
  const { getFlowOrgTreeRun, getFlowOrgTreeLoading, getFlowOrgList } = getFlowOrgTreeByOrgIDService();

  /**是否显示撤销弹窗*/
  const [invalidState, setInvalidState] = useState<Record<string, any>>({}); /**撤销弹窗*/

  /** 获取当前部门用户数据 */
  const { getUserRun, getUserLoading, getUserList } = getUserDataList((res: any) => {
    if (!(res && res?.msgFlag)) {
      message.error(res?.msg);
    }
  });

  /** 获取当前部门用户数据 */
  const changeGetUser = (value: string | number) => {
    contractForm?.setFieldValue('userID', '');
    getUserRun({
      /** 获取当前使用部门用户信息 */
      userDepartmentID: value,
    });
  };

  /** 获取当前人对象 */
  const getSelectUserInfo = (value: string | number, option: any) => {
    setSelectUserInfo(option);
  };

  /** 选择合同弹窗 */
  const handleSelectContract = () => {
    setContractVisible(true);
  };
  /** 选择材料弹窗 */
  const openMaterialModalStatus = () => {
    setOpenMaterialModal(true);
  };

  /** 处理工作流功能 权限 */
  const workflowPowerAllBtn = useMemo(() => {
    let pownerBtn: Record<string, any> = {
      revokeFlagBtn: false, //撤销按钮
      invalBoolBtn: false, //暂停开始按钮
      stopProcInstBtn: false, //流程作废接口
    };
    if (detailInfo?.state == `${getTenantID()}${ILoadMapTypeAll?.ASSET_TOASSET}1001`) {
      pownerBtn['revokeFlagBtn'] = true;
      pownerBtn['stopProcInstBtn'] = true;
    }

    const taskType: string = `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_TYPE}1001`;
    const taskHandInfo: Record<string, any> = detailInfo?.paramObject?.[taskType];
    if (
      taskHandInfo &&
      taskHandInfo?.mactivitiTaskList?.length > 0 &&
      taskHandInfo?.mactivitiTaskList?.[0]?.assigneePositionID == getPosIDs() &&
      taskHandInfo?.mactivitiTaskList?.[0]?.assigneeID == getUserID()
    ) {
      pownerBtn['invalBoolBtn'] = true;
    }
    return pownerBtn;
  }, [detailInfo]);

  /**
   * 新增编辑回调
   * @param res 接口返回数据
   * @param callType true 为新增回调  || false 为编辑回调
   */
  const updateAnnounceCallback = (res: any) => {
    if (res && res?.msgFlag) {
      message.success(res?.msg);
      if (submitState) {
        /** 保存新增编辑数据 */
        setDetailInfo(res?.obj);
        /** 打开工作流弹窗 */
        setWorkFlowInfoObj({
          selectFlowRows: res?.obj,
          showWorkFlowModal: true,
          saveNoDefaultFlowID: '',
        });
      } else {
        // setSubmitState(true);
        history.push({
          pathname: '/toAssetController/manage',
          state: {
            delRouterNameSource: history.location.pathname,
          },
        });
      }
    } else {
      message.error(res?.msg);
    }
  };

  /** 获取详情回调 */
  const updataGetDetail = (res: any) => {
    if (res && res?.msgFlag) {
      /** 详情数据 */
      setDetailInfo({
        ...res?.obj,
        // createTime: moment(res?.obj?.createTime).format('YYYY-MM-DD'), // 申请日期
      });
      toAssetControllerDispatch({
        type: IToAssetControllerActionEnum.SELECT_CONTRACT,
        payload: res?.obj.massetContractList,
      });
      toAssetControllerDispatch({
        type: IToAssetControllerActionEnum.SELECT_MATERIEL,
        payload: res?.obj.mAssetStuffassetList,
      });

      /** 是否是审核中 */
      if (
        res?.obj?.checkState === `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_CHECKRESULT}1000` &&
        res?.obj?.state === `${getTenantID()}${ILoadMapTypeAll.ASSET_TOASSET}1001`
      ) {
        setAuditSuccessState(true);
      }

      message.success(res?.msg);
    }
  };

  /** 工作流通过结束后调用改变状态的接口回调 */
  const approvedToAssetCallback = (res: Record<string, any>) => {
    if (res && res?.msgFlag) {
      message.success(res?.msg);
      history.push({
        pathname: '/toAssetController/manage',
        state: {
          delRouterNameSource: history.location.pathname,
        },
      });
    } else {
      message.error(res?.msg);
    }
  };

  /** 获取入库详情 */
  const { getDetailLoading, getDetailRun } = getDetailService(updataGetDetail);
  /** 提交入库申请 */
  const { addStorageLoading, addStorageRun } = addStorageService(updateAnnounceCallback);
  /** 编辑入库申请 */
  const { editStorageLoading, editStorageRun } = editStorageService(updateAnnounceCallback);
  /** 提交申请 */
  const { submitStorageLoading, submitStorageRun } = submitStorageService(updateAnnounceCallback);
  /** 工作流通过结束后调用改变状态的接口 */
  const { approvedToAssetLoading, approvedToAssetRun } = approvedToAssetSerivice(approvedToAssetCallback);

  /** 获取表单配置
   *  @pageType  传递的类型，是修改还是查看
   *  @record   当前项
   */
  const { config, methods } = getUpdateConfig({
    pageType: locationProps?.state?.pageType ? locationProps?.state?.pageType : '',
    record: locationProps?.state?.record ? (detailInfo ? Object.assign({}, locationProps?.state?.record, detailInfo) : locationProps?.state?.record) : {},
    openMaterialModalStatus,
    handleSelectContract,
    contractForm,
    loadMapInfo,
    mapLoading,
    curRes,
    changeGetUser,
    getFlowOrgList,
    getFlowOrgTreeLoading,
    getUserList,
    getUserLoading,
    getSelectUserInfo,
  });

  /** 暂存按钮  保存数据 */
  const handleSave = () => {
    if (materielList.length === 0) {
      message.error('材料信息不能为空！');
      return;
    }
    if (!submitState) {
      // 对表单进行校验，获取表单数据
      config.form.validateFields()?.then((values: any) => {
        delete values.assetOldPrice;
        values.massetContractList = [];
        values.mAssetStuffassetList = [];
        if (detailInfo?.massetContractList && detailInfo?.massetContractList.length !== 0) {
          // 合并合同信息
          for (let i = 0; i < contractList.length; i++) {
            let idx = detailInfo?.massetContractList?.findIndex((item: any) => {
              return item.id == contractList[i].id;
            });
            if (idx !== -1) {
              detailInfo.massetContractList[idx].effectiveMoney = contractList[i].effectiveMoney;
              values.massetContractList.push(detailInfo.massetContractList[idx]);
            } else {
              values.massetContractList.push(contractList[i]);
            }
          }
        } else {
          values.massetContractList = [...contractList];
        }
        if (detailInfo?.mAssetStuffassetList && detailInfo?.mAssetStuffassetList.length !== 0) {
          // 合并材料信息
          for (let i = 0; i < materielList.length; i++) {
            let idx = detailInfo?.mAssetStuffassetList?.findIndex((item: any) => {
              return item.stuffId == materielList[i].id || materielList[i].stuffId;
            });
            if (idx !== -1) {
              detailInfo.mAssetStuffassetList[idx].validNum = materielList[i].validNum;
              values.mAssetStuffassetList.push(detailInfo.mAssetStuffassetList[idx]);
            } else {
              let obj = {
                stuffId: materielList[i].id ? materielList[i].id : materielList[i].stuffId,
                validNum: materielList[i].validNum,
              };
              values.mAssetStuffassetList.push(obj);
            }
          }
        } else {
          for (let i = 0; i < materielList.length; i++) {
            let obj = {
              stuffId: materielList[i].id ? materielList[i].id : materielList[i].stuffId,
              validNum: materielList[i].validNum,
            };
            values.mAssetStuffassetList.push(obj);
          }
        }

        // 新增和修改接口
        if (locationProps?.state?.pageType == 'add') {
          values.createTime = moment(values?.createTime).format('YYYY-MM-DD HH:mm:ss');
          values.applyCode = locationProps?.state?.record.applyCode ? locationProps?.state?.record.applyCode : getInvoiceCode('CLZZC');
          values.useCompanyID = selectUserInfo?.userCompanyID ? selectUserInfo?.userCompanyID : '';
          values.usePositionID = selectUserInfo?.userPositionID ? selectUserInfo?.userPositionID : '';
          values.businessType = `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_TYPE}1017`;
          addStorageRun(values);
        } else {
          values.createTime = moment(values?.createTime).format('YYYY-MM-DD HH:mm:ss');
          delete detailInfo.mAssetStuffassetList;
          delete detailInfo.massetContractList;
          let obj = { ...detailInfo, ...values };
          editStorageRun(obj);
        }
      });
    } else {
      config.form.validateFields()?.then((values: any) => {
        delete values.assetOldPrice;
        values.massetContractList = [];
        values.mAssetStuffassetList = [];
        if (detailInfo?.massetContractList && detailInfo?.massetContractList.length !== 0) {
          // 合并合同信息
          for (let i = 0; i < contractList.length; i++) {
            let idx = detailInfo?.massetContractList?.findIndex((item: any) => {
              return item.id == contractList[i].id;
            });
            if (idx !== -1) {
              detailInfo.massetContractList[idx].effectiveMoney = contractList[i].effectiveMoney;
              values.massetContractList.push(detailInfo.massetContractList[idx]);
            } else {
              values.massetContractList.push(contractList[i]);
            }
          }
        } else {
          values.massetContractList = [...contractList];
        }
        if (detailInfo?.mAssetStuffassetList && detailInfo?.mAssetStuffassetList.length !== 0) {
          // 合并材料信息
          for (let i = 0; i < materielList.length; i++) {
            let idx = detailInfo?.mAssetStuffassetList?.findIndex((item: any) => {
              return item.stuffId == materielList[i].id || materielList[i].stuffId;
            });
            if (idx !== -1) {
              detailInfo.mAssetStuffassetList[idx].validNum = materielList[i].validNum;
              values.mAssetStuffassetList.push(detailInfo.mAssetStuffassetList[idx]);
            } else {
              let obj = {
                stuffId: materielList[i].id ? materielList[i].id : materielList[i].stuffId,
                validNum: materielList[i].validNum,
              };
              values.mAssetStuffassetList.push(obj);
            }
          }
        } else {
          for (let i = 0; i < materielList.length; i++) {
            let obj = {
              stuffId: materielList[i].id ? materielList[i].id : materielList[i].stuffId,
              validNum: materielList[i].validNum,
            };
            values.mAssetStuffassetList.push(obj);
          }
        }
        // 修改接口
        detailInfo.mAssetStuffassetList = [...detailInfo.mAssetStuffassetList, ...values.mAssetStuffassetList];
        detailInfo.massetContractList = [...detailInfo.massetContractList, ...values.massetContractList];
        detailInfo.createTime = moment(detailInfo?.createTime).format('YYYY-MM-DD HH:mm:ss');
        delete detailInfo.mAssetStuffassetList;
        delete detailInfo.massetContractList;
        let obj = {
          ...detailInfo,
          ...values,
          createTime: moment(values?.createTime).format('YYYY-MM-DD HH:mm:ss'), // 申请日期
        };
        editStorageRun(obj);
      });
    }
  };

  /** 提交按钮 */
  const handleSubmit = () => {
    if (!submitState) {
      setSubmitState(true);
      handleSave();
    } else {
      /** 打开工作流弹窗 */
      setWorkFlowInfoObj({
        selectFlowRows: detailInfo,
        showWorkFlowModal: true,
        saveNoDefaultFlowID: '',
      });
    }
  };

  /** 提交流程后跳转到管理页面 */
  const reloadManage = () => {
    setSubmitState(false);
    history.push({
      pathname: '/toAssetController/manage',
      state: {
        delRouterNameSource: history.location.pathname,
      },
    });
  };

  /** 返回tab子页面 */
  const tabsItem = () => {
    let items: any[] = [
      {
        label: '申请详情',
        key: '001',
        children: (
          <>
            <div className="commonTabsBodyDom">
              <div className={Cls('tabsBodyInfoDom', `${styleFixCls}updateFormBox`)}>
                <ScrollBarLayout style={{ padding: '5px 20px' }}>
                  <DescriptionsType config={config} />
                </ScrollBarLayout>
              </div>
              <div className="tabsBodyBottomBtn">
                <Space>
                  {/* {locationProps?.state?.pageType !== 'detail' || (detailInfo?.state == '100124371003' && detailInfo?.checkState == '100199021003') ? (
                    <Button type={'primary'} icon={<SaveOutlined />} onClick={handleSave}>
                      暂存
                    </Button>
                  ) : null} */}
                  {((!detailInfo?.state ||
                    (detailInfo?.state == '100124371000' && !detailInfo?.checkState) ||
                    (detailInfo?.state == '100124371003' && detailInfo?.checkState == '100199021003')) &&
                  detailInfo?.createrID == getUserID())|| locationProps?.state?.pageType === 'add' ? (
                    <Button
                      type={'primary'}
                      // icon={<CheckCircleOutlined />}
                      onClick={handleSubmit}
                    >
                      提交
                    </Button>
                  ) : null}
                  <Button danger onClick={closeCurrent}>
                    关闭
                  </Button>
                </Space>
              </div>
              {/* <div className="tabsBodyBottomBtn">
                <Space>
                  {locationProps?.state?.pageType == 'detail' ? (
                    <WorkflowHndTaskBtn
                      flowDetailInfo={detailInfo}
                      reloadCallback={() => {
                        getDetailRun(detailInfo?.id);
                        getUserRun({
                          userDepartmentID: detailInfo?.useDepartmentID,
                        });
                      }}
                      requestController={'assetApplyStuffasset'}
                      flowBusinessType={BGflowBusinessType()}
                    />
                  ) : null}
                </Space>
              </div> */}
            </div>
          </>
        ),
      },
    ];
    return items;
  };

  /**
   * 关闭切换流程modal方法
   * @isDefaultModal  点击确定 true,关闭切换流程zujian,打开发起流程组件  点击取消 false 关闭切换流程组件
   */
  const closeSwitchFlowModal = (isDefaultModal: boolean) => {
    if (isDefaultModal) {
      setWorkFlowInfoObj({
        ...workFlowInfoObj,
        showWorkFlowModal: true,
      });
    } else {
      setShowSwitchFlow(false);
    }
  };

  /** 监听选中的合同，以及材料列表，然后改变参考单价 */
  useEffect(() => {
    let total = 0;
    for (let i = 0; i < contractList.length; i++) {
      if (Object.keys(contractList[i]).includes('effectiveMoney')) {
        total += Number(contractList[i].effectiveMoney);
      } else {
        total += 0;
      }
    }
    for (let i = 0; i < materielList.length; i++) {
      total += Number(materielList[i].assetValue) * Number(materielList[i].validNum);
    }
    total = Number(formatDecimal(total));
    contractForm.setFieldValue('unitPrice', total);
  }, [materielList, contractList]);

  /** 监听审核状态 */
  useEffect(() => {
    if (
      auditSuccessState &&
      detailInfo?.checkState === `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_CHECKRESULT}1002` &&
      detailInfo?.state === `${getTenantID()}${ILoadMapTypeAll.ASSET_TOASSET}1002`
    ) {
      detailInfo.createTime = moment(detailInfo?.createTime).format('YYYY-MM-DD HH:mm:ss');
      approvedToAssetRun({ ...detailInfo, workflowResult: true });
    }
  }, [detailInfo?.checkState, detailInfo?.state]);

  // 获取详情
  useEffect(() => {
    /** 初始化请求组织机构 */
    let payload = {
      params: '0',
      flowType: '0',
    };
    getFlowOrgTreeRun(payload);
    if (locationProps?.state?.pageType != 'add') {
      getDetailRun(locationProps?.state?.record?.id);
      getUserRun({
        //获取当前部门用户信息
        userDepartmentID: locationProps?.state?.record?.useDepartmentID,
      });
    } else {
      getUserRun({
        //获取当前部门用户信息
        userDepartmentID: getUserDepID(),
      });
    }
  }, []);

  /** 申请页ref */
  const { confirm } = Modal;

  const closeCurrent = () => {
    confirm({
      title: '关闭',
      icon: <QuestionCircleOutlined />,
      content: '确定要关闭当前页吗？',
      okText: '确定',
      okType: 'primary',
      cancelText: '取消',
      onOk() {
        history.push({
          pathname: locationProps?.state?.returnPathName,
          state: {
            delRouterNameSource: history.location.pathname, //必传,要删除的路由名称
            returnPathName: locationProps?.state?.returnPathName,
          },
        });
      },
      onCancel() {},
    });
  };

  const changeRevoke = () => {
    setInvalidState({
      isShow: true,
      resObj: detailInfo,
    });
  };

  /** tabs 标签页操作 */
  const contactsTabsExtra = () => {
    return (
      <DetailInfoViewBottomBtn
        position="top"
        detailInfo={detailInfo}
        getDetailRun={getDetailRun}
        handleSubmit={handleSubmit}
        getUserRun={getUserRun}
        locationProps={locationProps}
        handleSave={handleSave}
        changeRevoke={changeRevoke}
      />
    );
  };

  return (
    <>
      <ToAssetControllerContext.Provider
        value={{
          prefixCls,
          styleFixCls,
          contractList,
          materielList,
          addMatrielList,
          curRes,
          contractForm,
          toAssetControllerDispatch,
        }}
      >
        <div className={'apply-update-UpdataIntentBox'}>
          <Spin spinning={getDetailLoading || addStorageLoading || editStorageLoading || submitStorageLoading || approvedToAssetLoading}>
            <Row className={`${styleFixCls}row`}>
              <Col span={24} className={`${styleFixCls}row-col`}>
                <Tabs
                  className={pageStyles['commonTabs']}
                  type="card"
                  onChange={(activeKey: string) => {}}
                  items={tabsItem()}
                  destroyInactiveTabPane={true}
                  tabBarExtraContent={contactsTabsExtra()}
                />
              </Col>
            </Row>

            <div>
              {/* 选择材料列表 */}
              {openMaterialModal && (
                <OpenMaterialModal
                  isShowModal={openMaterialModal}
                  contractForm={contractForm}
                  onClose={() => {
                    setOpenMaterialModal(false);
                  }}
                />
              )}
            </div>
            {/* 选择合同列表 */}
            {contractVisible && (
              <ContractModal
                curRes={curRes}
                isShowModal={contractVisible}
                onClose={() => {
                  setContractVisible(false);
                }}
              />
            )}

            {/* 撤销弹窗 */}
            {invalidState?.isShow && (
              <RevokeModal
                resObj={invalidState?.resObj}
                revokeRequestUrl={'/assetApplyStuffasset/revoke'}
                onClose={() => setInvalidState({})}
                reqBody={{ id: invalidState?.resObj?.id, state: `${getTenantID()}${ILoadMapTypeAll?.ASSET_TOASSET}1000` }}
                modalTip={
                  <div style={{ color: '#000' }}>
                    确认是否撤销【<span style={{ color: 'red' }}>{invalidState?.resObj?.applyTitle}</span>】的审核, 撤销后可重新提交！
                  </div>
                }
                reloadRequest={() => {
                  history.push({
                    pathname: locationProps?.state?.returnPathName,
                    state: {
                      delRouterNameSource: history.location.pathname, //必传,要删除的路由名称
                      returnPathName: locationProps?.state?.returnPathName,
                    },
                  });
                }}
              />
            )}

            {/* 工作流-----审批记录 */}
            {detailInfo?.paramObject?.[`${getTenantID()}${ILoadMapTypeAll.ALLFLOW_TYPE}1017`] && (
              <WorkflowChedkRecord
                curRes={curRes}
                dataDetailInfo={detailInfo}
                flowBusinessType={`${getTenantID()}${ILoadMapTypeAll.ALLFLOW_TYPE}1017`}
                requestController={requestController()}
                reloadPageCallback={() => {
                  getDetailRun({ id: detailInfo?.id });
                }} // 刷新方法-详情方法
                revokeStateID={`${getTenantID()}${ILoadMapTypeAll?.ASSET_TOASSET}1000`}
                allBtnFuncQuqry={workflowPowerAllBtn}
                tabPaneHeight={0.35}
                isCheckDrawer={true}
                isShowCollapse={isShowWorkRecord}
                changeCollapse={(val) => {
                  setIsShowWorkRecord(val);
                }}
                cancelStateId={`${getTenantID()}${ILoadMapTypeAll?.ASSET_TOASSET}1004`}
                isSyncArchive={true}
              />
            )}

            {/* 工作流-----发起流程审批弹窗 */}
            {workFlowInfoObj?.showWorkFlowModal && (
              <WorkflowSwitchModal
                openVisible={workFlowInfoObj?.showWorkFlowModal}
                businessInfoObj={workFlowInfoObj?.selectFlowRows}
                requestController={requestController()}
                orderType={workFlowInfoObj?.selectFlowRows?.orderType || orderType()}
                category={`${getTenantID()}${ILoadMapTypeAll.ALLFLOW_TYPE}1017`}
                // businessCategory={`${getTenantID()}${ILoadMapTypeAll.INTENTION_CATEGORY}1000`}
                businessCategory={``}
                selectFlowID={workFlowInfoObj?.saveNoDefaultFlowID}
                reloadInfoCallback={() => {
                  reloadManage();
                }}
                openFlowChangeModal={setShowSwitchFlow}
                onClose={() => {
                  setWorkFlowInfoObj({
                    ...workFlowInfoObj,
                    showWorkFlowModal: false,
                  });
                  history.push({
                    pathname: '/toAssetController/manage',
                    state: {
                      delRouterNameSource: history.location.pathname,
                    },
                  });
                }}
                replaceStrObj={{ own: 'own', workflowType: 'category' }}
              />
            )}

            {/* 挑选流程组件 */}
            {showSwitchFlow && (
              <WorkflowNoDefaultTable
                openVisibleSwitch={showSwitchFlow}
                onCloseSwitch={closeSwitchFlowModal}
                requestController={'assetApplyStuffasset'}
                orderType={workFlowInfoObj?.selectFlowRows?.orderType || orderType()}
                category={`${getTenantID()}${ILoadMapTypeAll.ALLFLOW_TYPE}1017`}
                businessCategory={`${getTenantID()}${ILoadMapTypeAll.ALLFLOW_TYPE}1017`}
                saveSelectFlowID={(flowId: string) => {
                  setWorkFlowInfoObj({
                    ...workFlowInfoObj,
                    saveNoDefaultFlowID: flowId,
                  });
                }}
                selectFlowID={workFlowInfoObj?.saveNoDefaultFlowID}
              />
            )}
          </Spin>
        </div>
      </ToAssetControllerContext.Provider>
    </>
  );
};

export default connect(({ baseLogin, navTab }: Record<string, any>) => ({
  curRes: baseLogin?.permissions,
  navTab,
}))(ToAssetControllerUpdateView);
